package dispatcher.gui.event;

import java.io.IOException;

import messages.persondispatcher.PersonCreationMessage;
import dispatcher.person.gui.network.PersonDispatcherGUIObserverThread;
import state.person.Person;

/**
 * This class is used to send messages from the GUI to the handler in change of taking to the 
 * Person Dispatcher
 * @author Caleb
 *
 */
public class PersonCreatedThread extends Thread {

	private Person person;
	private PersonDispatcherGUIObserverThread thread;
	
	/**
	 * The main constructor
	 * @param p The person to be entered into the system
	 * @param thread The handler thread
	 */
	public PersonCreatedThread(Person p, PersonDispatcherGUIObserverThread thread){
		super("PersonCreatedThread");
		this.person = p;
		this.thread = thread;
	}
	
	@Override
	public void run(){
		try {
			// Attempts to create a new person
			thread.sendPersonMessage(new PersonCreationMessage(this.person));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
